//引入express
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');

//实例化一个app对象
const app = express();

//引入user.js
const users = require('./rotuers/api/users')
const profiles = require('./rotuers/api/profiles')

// DB config
const db = require('./config/keys').mongoURI


// 使用body-parser中间件
app.use(bodyParser.urlencoded({expanded: false}))
app.use(bodyParser.json())


// Connect mongodb
mongoose.connect(db, {useNewUrlParser:true})
    .then(()=> console.log('Mongodb Connected'))
    .catch(err=>console.log(err))


// passport初始化
app.use(passport.initialize());
require("./config/passport")(passport);
// app.get('/', (req, res) => {
//     res.send('Hello World1122!')
// })

app.use('/api/users', users);
app.use('/api/profiles', profiles);
//创建一个端口号
const port = process.env.PORT || 5000;
// 监听这个端口号
app.listen(port, () => {
    console.log(`Server running on port ${ port }`)
})


